<?php

namespace App\Http\ViewComposers;

use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use App\Models\SiteMenu;

class CimoAdminComposer
{

    protected $site_menu=array();

    protected $child_menu=array();

    protected $menu_keys = 'index';


    protected $requestUri;

    protected $baidukey;

    protected $authUser;


    public function __construct()
    {

        $this->requestUri = Request::getRequestUri();

        $this->site_menu = SiteMenu::where('parent_id','=',0)->orderBy('display_order','ASC')->orderBy('menu_id','ASC')->get(); //

        foreach ($this->site_menu as $menu)
        {
            $this->child_menu[$menu->description] = SiteMenu::where('parent_id','=',$menu->menu_id)
                                                    ->orderBy('display_order','ASC')
                                                    ->orderBy('menu_id','ASC')
                                                    ->get();
            foreach ($this->child_menu[$menu->description] as &$chmenu)
            {
                $chmenu[$chmenu->description] = SiteMenu::where('parent_id','=',$chmenu->menu_id)
                                                ->orderBy('display_order','ASC')
                                                ->orderBy('menu_id','ASC')
                                                ->get();
            }
        }
        $this->authUser = Auth::user();
    }

    
    
    public function compose(View $view)
    {
        $view->with('site_menu', $this->site_menu);
        $view->with('child_menu',$this->child_menu);
        $view->with('request_uri',$this->requestUri);
        $view->with('menu_keys',$this->menu_keys);
        $view->with('authuser',$this->authUser);
    }


}